<template>
  <div class="goods-hot" ref="target">
    <h3 v-if="type === 1">24小时热销榜</h3>
    <h3 v-else-if="type === 2">周热销榜</h3>
    <h3 v-else-if="type === 3">总热销榜</h3>
    <GoodsItem v-for="item in list" :key="item.id" :goods="item"></GoodsItem>
  </div>
</template>

<script>
import GoodsItem from '@/views/category/components/goods-item.vue'
import { findHotGoods } from '@/api/goods'
import { useLazyData } from '@/hooks'
export default {
  components: { GoodsItem },
  name: 'GoodsHot',
  props: {
    type: {
      type: Number,
      default: 1
    },
    goodsId: {
      type: String,
      default: ''
    }
  },
  setup (props) {
    // 普通写法
    // findHotGoods({ id: props.goodsId, type: props.type }).then(({ result }) => {
    //   // console.log(result)
    // })
    // 💥 调用 useLazyData 数据懒加载，注意接口传参写法
    const { list, target } = useLazyData(() => findHotGoods({ id: props.goodsId, type: props.type }))
    return { list, target }
  }
}
</script>

<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  :deep(.goods-item) {
    background: #fff;
    width: 100%;
    margin-bottom: 10px;
    img {
      width: 200px;
      height: 200px;
    }
    p {
      margin: 0 10px;
    }
    &:hover {
      transform: none;
      box-shadow: none;
    }
  }
}
</style>
